package com.ccc.mr.flowsum_partition;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowCountMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
    Text k = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, FlowBean>.Context context) throws IOException, InterruptedException {
        String[] strings = value.toString().split("\t");
        String phone_num = strings[1];
        Long upFlow = Long.parseLong(strings[strings.length - 3]);
        Long downFlow = Long.parseLong(strings[strings.length - 2]);

        k.set(phone_num);
        v.setFlow(downFlow, upFlow);

        context.write(k, v);
    }
}
